#include "Pause.h"

CCScene* PauseLayer::scene(GameLayer* parentLayer)
{
    CCScene *scene = CCScene::create();
    
    PauseLayer *layer = PauseLayer::create();
    
	parentLayer->setTouchEnabled(false);
	layer->parentLayer = parentLayer;
    scene->addChild(layer);
    
    return scene;
}

bool PauseLayer::init()
{
    if(!CCLayerColor::initWithColor(ccc4(255, 255, 255, 0)))
    {
        return false;
    }
    
    winSize = CCDirector::sharedDirector()->getWinSize();
    
    dimLayer = CCLayerColor::create(ccc4(0, 0, 0, 100), winSize.width, winSize.height);
    dimLayer->setAnchorPoint(CCPointZero);
    dimLayer->setPosition(CCPointZero);
    this->addChild(dimLayer);
    
    popLayer = CCLayerColor::create(ccc4(0, 255, 0, 255), 300, 400);
    popLayer->setAnchorPoint(CCPointZero);
    popLayer->setPosition(ccp((winSize.width - popLayer->getContentSize().width)/2, (winSize.height - popLayer->getContentSize().height)/2));
    this->addChild(popLayer);


    CCMenu* pMenu = CCMenu::create();
	CCLabelTTF* pLabel = CCLabelTTF::create("Resume", "∏º¿∫ ∞ÌµÒ", 40);
	CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(pLabel, this, menu_selector(PauseLayer::doResume));
	pMenuItem->setPosition(ccp(winSize.width * 0.5f, winSize.height * 0.6f));
	pMenu->addChild(pMenuItem);
    
	pLabel = CCLabelTTF::create("Main Menu", "∏º¿∫ ∞ÌµÒ", 40);
	pMenuItem = CCMenuItemLabel::create(pLabel, this, menu_selector(PauseLayer::doMainMenu));
	pMenuItem->setPosition( ccp(winSize.width * 0.5f, winSize.height * 0.5f));
	pMenu->addChild(pMenuItem);
    
	pLabel = CCLabelTTF::create("Game Exit", "∏º¿∫ ∞ÌµÒ", 40);
	pMenuItem = CCMenuItemLabel::create(pLabel, this, menu_selector(PauseLayer::doGameExit));
	pMenuItem->setPosition( ccp(winSize.width * 0.5f, winSize.height * 0.4f));
	pMenu->addChild(pMenuItem);
    
	pMenu->setPosition(CCPointZero);
	this->addChild(pMenu);

    
    
    return true;
}

void PauseLayer::doResume()
{
	parentLayer->setTouchEnabled(true);
	CCDirector::sharedDirector()->resume();
    this->removeFromParentAndCleanup(true);
}

void PauseLayer::doMainMenu()
{
    CCDirector::sharedDirector()->resume();
    SceneController::runScene(MENU_SCENE);
}

void PauseLayer::doGameExit()
{
    CCDirector::sharedDirector()->end();
}

